#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int acc = 0;
	priority_queue<int, vector<int>, greater<int>> q;
	int Q, op, x;
	cin >> Q;
	while (Q--) {
		cin >> op;
		if (op == 2) {
			cout << q.top() + acc << endl;
			q.pop();
			continue;
		} else cin >> x;
		if (op == 1)
			q.push(x - acc);
		else
			acc += x;
	}
	return 0;
}
